// 抓取网络资源
var requs = require('request');
var fs = require('fs');
var path = require('path');
module.exports = function(url,dir,name) {
    var dirs = dir?dir:path.resolve(__dirname, '../static/upload');
    if(!fs.existsSync(dirs)) fs.mkdirSync(dirs,{recursive:true});
    var names = name ? name :url.split('/')[ url.split('/').length - 1];
    requs(url).pipe(fs.createWriteStream(dirs + '/' + names));
    return {state:'ok',dirs,names}
}